package com.hyz.listener;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyz.pojo.assetRetire.AssetRetire;
import com.hyz.service.AssetRetireService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 资产报废日志微服务控制层
 */
@Component
public class AssetRetireListener {
    @Autowired
    private AssetRetireService service;

    /**
     * 新增数据
     *
     * @param message json字符串
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "assetRetire.queue"),
            exchange = @Exchange(name = "assetRetire", type = ExchangeTypes.DIRECT),
            key = {"insertAssetRetire"}
    ))
    public void insertAssetRetire(String message) {
        AssetRetire assetRetire = JSON.parseObject(message, AssetRetire.class);
          service.save(assetRetire);
    }
}
